﻿@{
    Layout = null;
    Model.Intelligence_AutoAppraise AutoAppraiseData = ViewBag.AutoAppraise;
    string[] strs = AutoAppraiseData.AppraiseContents.Split('&');
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>管理工具</title>
    <!--SEO优化部分 & 全局样式部分-->
    @Html.Partial("_Title")
    <script src="~/Theme/layui/layui.js"></script>
    <script src="~/Theme/layer/layer.js"></script>
    <link href="~/Theme/css/IntelligenceManageCSS.css" rel="stylesheet" />
</head>
<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin">
        <!--头部-->
        @Html.Partial("_Top")
        <!--左侧-->
        <div class="layui-side layui-bg-black">
            <div class="layui-side-scroll">
                <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
                <ul class="layui-nav layui-nav-tree" lay-filter="test">
                    <li class="layui-nav-item"><a href="/IntelligenceManage/AutoResend">自动重发商品</a></li>
                    <li class="layui-nav-item layui-this"><a href="/IntelligenceManage/AutoAppraise">自动评价订单</a></li>
                    <li class="layui-nav-item"><a href="/IntelligenceManage/AutoWindow">自动橱窗位</a></li>
                    <li class="layui-nav-item"><a href="/IntelligenceManage/AutoStock">自动补库存</a></li>                   
                </ul>
            </div>
        </div>

        <div class="layui-body" style="">
            <fieldset class="layui-elem-field layui-field-title mt20" >
                <legend>自动评价设置</legend>
            </fieldset>
            <div class="layui-row">
                <div class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">评价开关</label>
                        <div class="layui-input-block">
                            @if (AutoAppraiseData.IsAutoAppraise)
                            {
                                <input type="checkbox" name="open" checked="" lay-skin="switch" lay-text="开启|关闭">
                            }
                            else
                            {
                                <input type="checkbox" name="open" lay-skin="switch" lay-text="开启|关闭">
                            }
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">评价日志</label>
                        <div class="layui-input-block">
                            <span>今日已评价的订单：<a><span class="layui-badge">@ViewBag.TodayLog</span>个</a></span>，
                            <span>共评价的订单：<a><span class="layui-badge">@ViewBag.Atotalof</span>个</a></span>
                        </div>
                    </div>

                    <div class="layui-form-item" pane="">
                        <label class="layui-form-label">评价内容</label>
                        <div class="layui-input-block">
                            <h3>设置评价内容(<span class="f12 font-red">可设置多条评价内容，系统会多条进行随机追评</span>)</h3>
                            <div id="AppraaiseContent">

                                @for (int i = 0; i < strs.Length; i++)
                                {
                                    <div class="layui-row">
                                        <div class="layui-col-xs6 zdpj_zp">
                                            <textarea class="zdpj_tet" cols="20"  name="ContentBody" rows="2">@strs[i]</textarea>
                                        </div>
                                        <div class="layui-col-xs6">
                                            <div>
                                                <a class="layui-btn layui-btn-xiao layui-btn-danger DelAppraise"><i class="layui-icon"></i>删除</a>
                                            </div>
                                        </div>
                                    </div>
                                }                                                                                  
                            </div>
                            <div class="">
                                <a class="layui-btn layui-btn-xiao layui-btn-normal AddAppraise"> <i class="layui-icon"></i>增加</a>                              
                            </div>  
                                                              
                        </div>

                       
                    </div>
                    
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">注意事项</label>
                        <div class="layui-input-block mt20 border-p1-c1">
                            <ul class="ih30 f12">
                                <li><span class="layui-badge-dot"></span>1.建议评语精简单，字数不超过50个中文字符，不要带网址，否则评价可能会失败。</li>
                                <li><span class="layui-badge-dot"></span>2.请经常登录系统避免因授权过期。</li>
                                <li><span class="layui-badge-dot"></span>3.如使用过程中遇到任何问题，请及时与软件开发者联系。</li>
                            </ul>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn submitbtn" >保存设置</button>
                        </div>
                    </div>
                </div>
            </div>
            <input type="hidden" value="@AutoAppraiseData.MemberId" id="MemberId" />
            <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
            <script>
                layui.use(['form', 'layedit', 'laydate'], function () {
                 
                    $(".submitbtn").click(function () {
                     
                        var appraiseContents = new Array()
                        $("*[name=ContentBody]").each(function () {
                            var crrunetval = $(this).val().trim()
                            if (crrunetval != "") {
                                var str1 = crrunetval.replace(/&/g, "")
                                appraiseContents.push(str1)
                            }
                        })

                        var MemberId = $("#MemberId").val();
                        var open = $("input[name='open']").prop('checked')
                        var newappraiseContents = appraiseContents.join("&");
                        
                        var data = JSON.stringify({ MemberId: MemberId, open: open, appraiseContents: newappraiseContents });
                        //提示弹层
                        layer.msg('正在提交保存...', { icon: 16, shade: [0.5, '＃f5f5f5'], scrollbar: false, offset: '300px', time: 50000 });
                        $.ajax({
                            url: "/api/IntelligenceManageAPI/UpdateAutoAppraise",
                            type: "Post",
                            dataType: "json",
                            data: { data: data },
                            success: function (data) {

                                //关闭弹层提示
                                layer.closeAll();

                                if (data == true) {
                                    layer.msg('保存成功', {
                                        offset: '60px'
                                    });
                                }
                                else {
                                    layer.msg('保存失败', {
                                        offset: '60px'
                                    });
                                }
                            }
                        })                                                               
                    })                                         
                });


                //添加删除评语
                $(function () {
                    $(".DelAppraise").unbind("click");
                    $(".DelAppraise").click(function () {

                        $(this).parent().parent().parent().remove();
                    })
                    $(".AddAppraise").click(function () {
                        var htmls = "";
                        htmls += " <div class='layui-row'>";
                        htmls += "<div class='layui-col-xs6 zdpj_zp'>";
                        htmls += "<textarea class='zdpj_tet' cols='20'  name='ContentBody' rows='2'>你好，感谢你的惠顾！</textarea>";
                        htmls += "</div>";
                        htmls += "<div class='layui-col-xs6'>";
                        htmls += "<div>";
                        htmls += "<a class='layui-btn layui-btn-xiao layui-btn-danger DelAppraise'><i class='layui-icon'></i>删除</a>";
                        htmls += "</div>";
                        htmls += "</div>";
                        htmls += "</div>";

                        $("#AppraaiseContent").append(htmls);

                        $(".DelAppraise").unbind("click");
                        $(".DelAppraise").click(function () {

                            $(this).parent().parent().parent().remove();
                        })
                    })
                })

            </script>

        </div>
        <!--底部-->
        @*@Html.Partial("_Foot")*@
    </div>
</body>
</html>



